<?php 
	Class packagereview extends CI_Controller{
		public function __construct(){
			parent::__construct();
			$this->load->model('model_packagereview');	
			$this->load->model('model_package');
		}
		
		public function index(){
			if(isset($_GET['packageid'])){
				$data['package']=$this->model_package->getdata(intval($_GET['packageid']));
				$data['data']=$this->model_packagereview->getByPackageid(intval($_GET['packageid']));	
			}
			$data["template"]="package/package_review";
			$this->load->view("layout",$data);
		}
		
		public function edit(){
			if(isset($_GET["id"])){
				$data["detail"]	= $this->model_packagereview->getdata(intval($_GET['id']));
			}else $data['detail']=NULL;	
			
			$data["template"]="package/packagereview_edit";
			$this->load->view("layout",$data);
		}
		
		public function update(){
			if(isset($_GET["id"])){
				$data['name']=$_POST['name'];
				$data['title']=$_POST['title'];
				$data['contents']=$_POST['contents'];
				$data['createdate']=date("Y-m-d",strtotime($_POST['createdate']));
				$data['mark']=$_POST['mark'];
				$data['packageid']=$_GET['packageid'];
				$this->model_packagereview->update($data,intval($_GET["id"]));				
				header('Location: '.base_url().'admin/packagereview/index?packageid='.intval($_GET['packageid']));
			}	
		}
		
		public function insert(){
			$data['name']=$_POST['name'];
				$data['title']=$_POST['title'];
				$data['contents']=$_POST['contents'];
				$data['createdate']=date("Y-m-d",strtotime($_POST['createdate']));
				$data['mark']=$_POST['mark'];
				$data['packageid']=$_GET['packageid'];
				$this->model_packagereview->add($data);		
				header('Location: '.base_url().'admin/packagereview/index?packageid='.intval($_GET['packageid']));
		}
		
		public function delete(){
			if(isset($_GET["id"])){
				$this->model_packagereview->del(intval($_GET["id"]));	
				header('Location: '.base_url().'admin/packagereview/index?packageid='.intval($_GET['packageid']));
			}	
		}
	}
?>